//基本类型
var num: number;
num = 123;
var str: string;
str = "123";
var boolean: boolean;
boolean = false;
var undefine: undefined;
undefine = undefined;
var nul: null;
nul = null;
//其它类型
//类型推断 联合类型
var data: any;
var anything;
anything = 1;

// var num12: number;
// num12 = null;

data = 123;
data = "123";
var data2: string | boolean;
data2 = "123";

var nosure = 123; //number
// nosure = "asd"; //报错，因为上面的类型推断

var arr: number[];
// arr = ["123", 1, 1, 2];
var arr1: string[];
arr1 = ["1", "2", "3", "..."];
//type[] 这里是[整体上]是什么类型

// 方案二 数组
var arr2: Array<number>;
// arr2 = [1, 2, "32"];
//Array<type>
var arr3: Array<boolean>;
arr3 = [false, true];

// 对象约束
var obj: {
  name: string;
  age: number;
} = { name: "wxs", age: 10 };

// 方案二obj 去除重复写代码冗余
interface User {
  name: string;
  age: number;
  gender: string;
  address: string;
}
var user1: User = {
  name: "imycode",
  age: 0,
  gender: "male",
  address: "fujian fuzhou",
};
//
// console.log(num + " " + str + " " + boolean + " " + undefine + " " + nul);

/* 函数类型 */
var a = function (params: number): number {
  return params;
};

console.log(a(1));

function add(a: number, b: number): void {
  console.log(`a+b=${a + b}`);
}
add(100, 1000);
